<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* standalone version of showMap - without dependencies on top.HEURIST
* Timemap = Mapstraction+Timeline
*
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  Viewers/Map
*/

-->

<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>

<!-- yui layout -->

<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/reset-fonts-grids/reset-fonts-grids.css">
<!-- Skin CSS files resize.css must load before layout.css -->
<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/assets/skins/sam/resize.css">
<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/assets/skins/sam/layout.css">
<!-- Utility Dependencies -->
<script src="../../external/yui/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="../../external/yui/2.8.2r1/build/dragdrop/dragdrop-min.js"></script>
<script src="../../external/yui/2.8.2r1/build/element/element-min.js"></script>
<!-- Optional Animation Support
<script src="../../external/yui/2.8.2r1/build/animation/animation-min.js"></script> -->
<!-- Optional Resize Support -->
<script src="../../external/yui/2.8.2r1/build/resize/resize-min.js"></script>
<!-- Source file for the Layout Manager -->
<script src="../../external/yui/2.8.2r1/build/layout/layout-min.js"></script>


<!-- timemap/timeline scripts -->

	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

	<script type="text/javascript">
			RelBrowser = {
						//baseURL: "http://heuristscholar.org/h3-ao/",
						pipelineBaseURL: "../"
			};

//	Timeline_urlPrefix = RelBrowser.baseURL + "external/timemap.2.0/lib/";

/*      Timeline_ajax_url   = RelBrowser.baseURL + "external/timeline_2.3.0/timeline_ajax/simile-ajax-api.js";
      Timeline_urlPrefix  = RelBrowser.baseURL + "external/timeline_2.3.0/timeline_js/";
      Timeline_parameters = 'bundle=true'; */

	Timeline_urlPrefix = "../../external/timemap.2.0/lib/timeline/";
	Timeline_ajax_url = "../../external/timemap.2.0/lib/timeline/timeline_ajax/simile-ajax-api.js";

	var showMap;
	</script>

<link href="../../external/jquery/jquery-ui-1.8.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../external/jquery/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="../../external/jquery/jquery-ui-1.8.13.custom.min.js"></script>

<!-- <script type="text/javascript" src="../../external/timemap.2.0/lib/jquery-1.4.4.min.js"></script> -->
<script type="text/javascript" src="../../external/timemap.2.0/lib/mxn/mxn.js?(googlev3)"></script>

<script type="text/javascript" src="../../external/timemap.2.0/lib/markerclusterer.js"></script>
<script type="text/javascript" src="../../external/timemap.2.0/lib/timeline/timeline-api.js?bundle=true"></script>
<!--
<script type="text/javascript" src="../../external/timemap.2.0/lib/timeline-1.2.js"></script>
<script type="text/javascript" src="../../external/timemap.2.0/lib/timeline-2.3.0.js"></script>
<script type="text/javascript" src="../../external/timeline_2.3.0/timeline_js/timeline-api.js"></script>
-->

<script src="../../external/timemap.2.0/src/timemap.js" type="text/javascript"></script>
<script src="../../external/timemap.2.0/src/param.js" type="text/javascript"></script>
<script src="../../external/timemap.2.0/src/manipulation.js" type="text/javascript"></script>
<script src="../../external/timemap.2.0/src/loaders/xml.js" type="text/javascript"></script>
<script src="../../external/timemap.2.0/src/loaders/kml.js" type="text/javascript"></script>

<script src="../../viewers/map/mapping.js" type="text/javascript"></script>
<script src="../../common/js/temporalObjectLibrary.js" type="text/javascript"></script>

<!--
					<script src="{$urlbase}js/gmapimage.js" type="text/javascript"/>
-->
<style type="text/css">
body {
	font: 10px Verdana, Geneva, sans-serif;
}
#map {
	margin-bottom: 8px;
	overflow: hidden;
	border: 1px solid #320a0a;
}
#map.image {
	height: 512px;
	margin-bottom: 17px;
}
#map.full {
	height: 100%;
}
#map.entity-map {
	height: 180px;
}
#map.hide {
	display: none;
}
.map-description {
	margin-bottom: 20px;
}

#timeline {
	border: 1px solid #320a0a;
	height:100%;
	overflow-x:hidden;
	overflow-y:auto;
}

#timeline-zoom {
	position: absolute;
	top: 3px;
	left: 3px;
	z-index: 2000;
	visibility: visible;
}
#timeline-zoom div {
	cursor: pointer;
}
#timeline.hide, #timeline-zoom.hide {
	position: absolute;
	visibility: hidden;
}

#timeline.entity-timeline .timeline-event-icon,
#timeline.entity-timeline .timeline-event-label,
#timeline.entity-timeline .timeline-event-tape {
	cursor: default;
}

/* for transparency slider*/
.ui-slider .ui-slider-handle {width: 0.25em;height:0.75em;}
.ui-slider-horizontal .ui-slider-handle {
  						margin-left: -0.3em;
    					top: -0.3em;
}

#rec_popup{
	color:green;
	display:inline-block;
	text-align:left;
	padding-left:3px;
	padding-top:3px;
}

#errorMsg{
	width:100%;
	height:99%;
	background-color:#FFF;
	text-align:center;
	vertical-align: middle;
}
#errorMsg span, .errorMsg span, div#errorMsg span{
	background-color: rgba(100, 100, 100, 0.6);
	background:-moz-linear-gradient(center top , rgba(100, 100, 100, 0.6), rgba(100, 100, 100, 0.9)) repeat scroll 0 0 transparent;
	background:-webkit-gradient(linear, left top, left bottom, from(rgba(100, 100, 100, 0.6)), to(rgba(100, 100, 100, 0.9)));
	border: 1px solid #999;
	-moz-border-radius:3px;
	-webkit-border-radius:3px;
	border-radius:3px;
	padding:3px;
	font-size:14px;
	color:#FFF;
}

.wrap {
	display:table;
	width:100%;
	height:90%;
	-webkit-border-bottom-right-radius:5px;
	border-bottom-right-radius: 5px;
	-moz-border-radius-bottomright:5px;
	margin:6px;
}
.wrap div {
	display:table-cell;
}

</style>

</head>

<body class="yui-skin-sam">

		<script>

	//find db parameter (similar in utilsLoad)
	function parseParams(paramString) {
		if (! paramString) {
			paramString = window.location.search;
		}
		if (paramString.charAt(0) == '?') {
			paramString = paramString.substring(1);
		}

		paramString = paramString.replace(/[+]/g, ' ');	// frustratingly, decodeURIComponent does not decode '+' to ' '

		var parmBits = paramString.split('&');
		var parms = {};
		for (var i=0; i < parmBits.length; ++i) {
			var equalPos = parmBits[i].indexOf('=');
			var parmName = decodeURIComponent(parmBits[i].substring(0, equalPos));
			if (equalPos >= 0) {
				parms[parmName] = decodeURIComponent(parmBits[i].substring(equalPos+1));
			} else {
				parms[parmName] = null;
			}
		}

		return parms;
	}

	var params = parseParams();
	if(!params['db']){
		params['db'] = 'sandpit5'; //HARDCODED
	}

	var HEURIST = {tmap:null};

	var installDir = window.location.protocol+"//"+window.location.host+
		window.location.pathname.replace(/(((admin|common|export|external|hapi|help|import|records|search|viewers)\/.*)|(index.*))/, "");
	var HRST = {
		VERSION: "3.1.0",
		basePath: installDir,
		iconBaseURL: installDir + "/HEURIST_FILESTORE/" + params['db'] + "/rectype-icons/",
		external_publish: true,
		database: {
			name: params['db']
			},
		util:{
			isnull: function(obj){
				return ( (typeof obj==="undefined") || (obj===null));
			},

	sendRequest: function(url,callback,postData) {
		// if we don't have a fully formed or root URL then prepend the base path
		if (! url.match(/^http:/)  &&  ! url.match(/^\//))
			url = HRST.basePath + url;
		var file = url;
		var req = HRST.util.createXMLHTTPObject();
		if (!req) return;
		var method = (postData) ? "POST" : "GET";
		req.open(method,url,true);// set for asynch call
		if (postData)
			req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			req.onreadystatechange = function () {// callback for ajax object
				if (req.readyState != 4) return;
				if (req.status != 200 && req.status != 304) {
					if (req.status == 404) {
						alert('H-Util HTTP error file not found' + req.status + " " +file);
					}else if (req.status){
						alert('H-Util HTTP error ' + req.status);
					}
					return;
				}
				callback(req);
			}
		if (req.readyState == 4) return;
		req.send(postData);
	},

	XMLHttpFactories: [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	],

	createXMLHTTPObject: function() {
		var xmlhttp = false;
		for (var i=0;i<HRST.util.XMLHttpFactories.length;i++) {
			try {
				xmlhttp = HRST.util.XMLHttpFactories[i]();
			}
			catch (e) {
				continue;
			}
			break;
		}
		return xmlhttp;
	},

	xhrFormSubmit: function(form, callback) {
	// submit a form via XMLHttpRequest;
	// call the callback with the response text when it is done
		var postData = "";
		for (var i=0; i < form.elements.length; ++i) {
			var elt = form.elements[i];

			// skip over un-selected options
			if ((elt.type == "checkbox"  ||  elt.type == "radio")  &&  ! elt.checked) continue;

			// FIXME: deal with select-multiple at some stage   (perhaps we should use | to separate values)
			// place form data into a stream of name = value pairs
			if (elt.strTemporal && (elt.strTemporal.search(/\|VER/) != -1)) elt.value = elt.strTemporal;	// saw fix to capture simple date temporals.
			if (postData) postData += "&";
			postData += encodeURIComponent(elt.name) + "=" + encodeURIComponent(elt.value);
		}

		HRST.util.sendRequest((form.getAttribute && form.getAttribute("jsonAction")) || form.action, callback, postData);
	},

	evalJson: function() {
		// Note that we use a different regexp from RFC 4627 --
		// the only variables available now to malicious JSON are those made up of the characters "e" and "E".
		// EEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEeEEEEEEEEEE
		var re1 = /"(\\.|[^"\\])*"|true|false|null/g;
		var re2 = /[^,:{}\[\]0-9.\-+Ee \n\r\t]/;
		return function(testString) {
			return ! re2.test(testString.replace(re1, " "))  &&  eval("(" + testString + ")");
		};
	}(),

	getJsonData: function(url, callback, postData) {
		HRST.util.sendRequest(url, function(xhr) {

			var obj = HRST.util.evalJson(xhr.responseText);
			if(!obj) {
				alert("Unknow error");
			}else if (obj.error) {
				alert(obj.error);
				obj = null;
			}else if(obj.errors && obj.errors.length>0){
				var rep = obj.errors.join(" ");
				alert(rep);
				obj = null;
			}
			if (callback) callback(obj);
		}, postData);
	},

		} //end util
	};


		</script>
		<!-- script type="text/javascript" src="../../common/js/utilsLoad.js"></script>
		<script type="text/javascript" src="../../common/js/utilsUI.js"></script -->
		<script type="text/javascript" src="../../viewers/map/showMap.js"></script>

		<div id="mapcontainer">
				<div id="map" class="full"></div>
		</div>

		<div id="timelinecontainer">
				<div id="timeline"></div>
				<div id="timeline-zoom"></div>
		</div>

		<div id="mapreportcontainer">
		</div>

<script type="text/javascript">

	//
	//  starts initialization on load completion of this window
	function loadHandler(){

		RelBrowser.baseURL = HRST.basePath;
		RelBrowser.iconBaseURL =  HRST.iconBaseURL;
		RelBrowser.database = HRST.database.name;

		//Timeline_urlPrefix = HRST.basePath + "external/timemap.2.0/lib/";

		window.showMap = new ShowMap();
	}

	YAHOO.util.Event.addListener(window, "load", loadHandler );

</script>

</body>
</html>
